/*
ID: icerupt1
PROG: holstein
LANG: C++11
*/
#include <fstream>
#include <iostream>
#include <algorithm>

std::ifstream fin {"holstein.in" };
std::ofstream fout{"holstein.out"};

int const max_type = 32;
int const maxn = 16;
int vitamin[max_type];
int da[maxn][max_type];
int v, n;

int bit_count_one(int x)
{
	x = (x & 0x55555555) + ((x>>1) & 0x55555555);
	x = (x & 0x33333333) + ((x>>2) & 0x33333333);
	x = (x & 0x0F0F0F0F) + ((x>>4) & 0x0F0F0F0F);
	x = (x & 0x00FF00FF) + ((x>>8) & 0x00FF00FF);
	x = (x & 0x0000FFFF) + ((x>>16)& 0x0000FFFF);
	return x;
}

bool judge(int x)
{
	int check[v];
	std::fill(check, check + v, 0);
	for (int i = n-1; i >= 0; i--, x >>= 1) {
		if (!(x&1)) continue;
		for (int j = 0; j < v; j++) check[j] += da[i][j];
	}
	for (int i = 0; i < v; i++)
		if (check[i] < vitamin[i]) return false;
	return true;
}

void print(int x)
{
	bool choose[n];
	std::fill(choose, choose + n, 0);
	for (int i = n-1; i >= 0; i--, x >>= 1)
		if (x&1) choose[i] = true;
	for (int i = 0; i < n; i++)
		if (choose[i]) {
			std::cout << ' ' << i + 1;
			fout << ' ' << i + 1;
		}
	std::cout << '\n';
	fout << '\n';
}

int main()
{
	fin >> v;
	for (int i = 0; i < v; i++) fin >> vitamin[i];
	fin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < v; j++) fin >> da[i][j];

	int select = 0, min = n + 1;
	for (int i = (1<<n) - 1; i > 0; i--) {
		if (bit_count_one(i) >= min) continue;
		if (judge(i)) {
			select = i;
			min = bit_count_one(i);
		}
	}
	std::cout << min;
	fout << min;
	print(select);
}
